package com.yanqu.road.server.logic.recharge;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.recharge.RechargeOrder;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eCardType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CardModule;
import com.yanqu.road.server.webservice.GamePublicFunction;

/**
 * 特权卡
 */
public class CardRecharge extends BaseRecharge {

    public CardRecharge(GamePlayer player, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(player, mallInfo, activityInfo);
    }

    @Override
    protected boolean isRepeatedBuy(String orderNo) {
        if(GameConfig.WEEK_CARD_MALL_ID == mallInfo.getMallId()){//月卡还未到购买期间
            return !player.getModule(CardModule.class).canBuyCard(eCardType.MonthCard.getValue());
        }else if(GameConfig.LIFE_CARD_MALL_ID == mallInfo.getMallId()){//年卡还未到购买期间
            return !player.getModule(CardModule.class).canBuyCard(eCardType.YearCard.getValue());
        }else if(GameConfig.PRIVILEGE_WEEK_CARD_MALL_ID == mallInfo.getMallId()){//直购周卡
            return !GamePublicFunction.weekCardCanBuy(player.getUserId(), mallInfo.getMallId());
        }
        return false;
    }

    @Override
    protected void repeatedBuyLogic() {
//        if(GameConfig.WEEK_CARD_MALL_ID == mallInfo.getMallId()){
//            player.getModule(CardModule.class).addCard(eCardType.MonthCard.getValue(), false);
//        }else if(GameConfig.LIFE_CARD_MALL_ID == mallInfo.getMallId()){
//            player.getModule(CardModule.class).addCard(eCardType.YearCard.getValue(), false);
//        }
    }

    @Override
    protected String addMall(String orderNo, RechargeOrder rechargeOrder) {
        String reward = "";
        if(GameConfig.WEEK_CARD_MALL_ID == mallInfo.getMallId()){//月卡
            reward = player.getModule(CardModule.class).addCard(eCardType.MonthCard.getValue(), true, mallInfo.getMallId(), rechargeOrder);
        }else if(GameConfig.LIFE_CARD_MALL_ID == mallInfo.getMallId()){//年卡
            reward = player.getModule(CardModule.class).addCard(eCardType.YearCard.getValue(), true, mallInfo.getMallId(), rechargeOrder);
        }else if(GameConfig.PRIVILEGE_WEEK_CARD_MALL_ID == mallInfo.getMallId()
                || GameConfig.SUBSCRIBE_WEEK_CARD_MALL_ID == mallInfo.getMallId()){//周卡
            reward = player.getModule(CardModule.class).addCard(eCardType.WeekCard.getValue(), false, mallInfo.getMallId(), rechargeOrder);
        }
        logger.info("订单: {}, 购买 特权卡商品: {}", orderNo, mallInfo.getMallId());
        return reward;
    }

}
